#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_fop_prop.info <<'%EOF%'
   cc_fop_prop
   -----------
   Molecule:         CO in C2v
   Wave Function:    CCS, CC2 / aug-cc-pVDZ
   Test Purpose:     First-order one-electron properties
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_fop_prop.mol <<'%EOF%'
BASIS
aug-cc-pVDZ
CC2 relaxed FOP
test calculation
    2    2  X  Y  Z   1.00D-15
        6.0   1
C     0.0000000000000000  0.0000000000000000 1.21824313000000000       *
        8.0   1
O     0.0000000000000000  0.0000000000000000 -.91397310000000000       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_fop_prop.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
.THETA
.EFGCAR
.SECMOM
.DARWIN
.MASSVELO
**WAVE FUNCTION
.CC
*SCF INP
.THRESH
 1.0D-10
.DOUBLY OCCUPIED
 5 1 1 0
*CC INP
.CCS
.CC2
.PRINT
 6
.THRENR
1.0D-10
.THRLEQ
1.0D-07
*CCFOP
.ALLONE
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_fop_prop.check
cat >>cc_fop_prop.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy: * -112\.75469112100" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * -113\.058739208" $log | wc -l`
CRIT3=`$GREP "Total CC2   energy: * -113\.065798167" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=5
ERROR[1]="ENERGIES NOT CORRECT"


# CCS first order properties :
CRIT1=`$GREP  "z * 0*\.1022163[0-9] * 0*\.2598080[0-9] * 0*\.866626[34]" $log | wc -l`
CRIT2=`$GREP  "1 * ( |0)\.7910107. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT3=`$GREP  "2 * ( |0)\.0000000. * ( |0)\.7910107. * ( |0)\.0000000" $log | wc -l`
CRIT4=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. * -1\.5820214" $log | wc -l`
CRIT5=`$GREP  "1 * 7\.6198238. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT6=`$GREP  "2 * ( |0)\.0000000. * 7\.6198238. * ( |0)\.0000000" $log | wc -l`
CRIT7=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. * 24\.7893178" $log | wc -l`
CRIT8=`$GREP  "Alfa\*\*2 Invariant: * 178\.03534" $log | wc -l`
CRIT9=`$GREP  "Beta\*\*2 Invariant: * 294\.79152" $log | wc -l`
CRIT10=`$GREP "Isotropic Property:  * 13\.34298. a\.u\." $log | wc -l`
CRIT11=`$GREP "Property anisotropy invariant: * 17\.16949. a\.u\." $log | wc -l`
CRIT12=`$GREP "1 * ( |0)\.5179949. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT13=`$GREP "2 * ( |0)\.0000000. * ( |0)\.5179949. * ( |0)\.0000000" $log | wc -l`
CRIT14=`$GREP "3 * ( |0)\.0000000. * ( |0)\.0000000. * -1\.0359899" $log | wc -l`
CRIT15=`$GREP "1 * ( |0)\.2598640. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT16=`$GREP "2 * ( |0)\.0000000. * ( |0)\.2598640. * ( |0)\.0000000" $log | wc -l`
CRIT17=`$GREP "3 * ( |0)\.0000000. * ( |0)\.0000000. * ( -|-0)\.5197280" $log | wc -l`
CRIT18=`$GREP "O * 17 * Vx = * ( |0)\.25986. * \-1\.56188. * (\-|\-0)\.55796." $log | wc -l`
CRIT19=`$GREP "O * 17 * Vy = * ( |0)\.25986. * \-1\.56188. * (\-|\-0)\.55796." $log | wc -l`
CRIT20=`$GREP "O * 17 * Vz = * (\-|\-0)\.51972. * 3\.12377. * 1\.11593." $log | wc -l`
CRIT21=`$GREP "   1-elec\. Darwin term: * 0*\.26055216[0-9]" $log | wc -l`
CRIT22=`$GREP "   Mass-Velocity term: * ( -|-0)\.32718385[0-9]" $log | wc -l`
CRIT23=`$GREP "   Mass-Velocity \+ 1-elec\. Darwin terms\: * ( -|-0)\.06663168[0-9]" $log | wc -l`
CRIT24=`$GREP "Ecorr = * -112\.75469112100" $log | wc -l`
TEST[2]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7  \+ $CRIT8  \+ $CRIT9  \+ $CRIT10 \+ \
              $CRIT11 \+ $CRIT12 \+ $CRIT13 \+ $CRIT14 \+ $CRIT15 \+ \
              $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ $CRIT19 \+ $CRIT20 \+ \
              $CRIT21 \+ $CRIT22 \+ $CRIT23 \+ $CRIT24`
CTRL[2]=24
ERROR[2]="CCS FIRST ORDER PROPERTIES NOT CORRECT"

# CC2 first order properties :
CRIT1=`$GREP  "z * (\-|\-0)\.1278271[0-9] * (\-|\-0)\.3249042[0-9] * \-1\.0837639." $log | wc -l`
CRIT2=`$GREP  "1 * ( |0)\.8017775. * ( |0)\.0000000. * ( |0)\.000000" $log | wc -l`
CRIT3=`$GREP  "2 * ( |0)\.0000000. * ( |0)\.8017775. * ( |0)\.0000000" $log | wc -l`
CRIT4=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. * -1\.6035551" $log | wc -l`
CRIT5=`$GREP  "1 * 7\.7634090. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT6=`$GREP  "2 * ( |0)\.0000000. * 7\.7634090. * ( |0)\.0000000" $log | wc -l`
CRIT7=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. * 24\.9544367" $log | wc -l`
CRIT8=`$GREP  "Alfa\*\*2 Invariant: * 182\.08133" $log | wc -l`
CRIT9=`$GREP  "Beta\*\*2 Invariant: * 295\.53143" $log | wc -l`
CRIT10=`$GREP "Isotropic Property:  * 13\.49375. a.u." $log | wc -l`
CRIT11=`$GREP "Property anisotropy invariant: * 17\.19102. a\.u\." $log | wc -l`
CRIT12=`$GREP "1 * ( |0)\.3959310. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT13=`$GREP "2 * ( |0)\.0000000. * ( |0)\.3959310. * ( |0)\.0000000" $log | wc -l`
CRIT14=`$GREP "3 * ( |0)\.0000000. * ( |0)\.0000000. * ( -|-0)\.791862(0|1)" $log | wc -l`
CRIT15=`$GREP "1 * ( |0)\.2806310. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT16=`$GREP "2 * ( |0)\.0000000. * ( |0)\.2806310. * ( |0)\.0000000" $log | wc -l`
CRIT17=`$GREP "3 * ( |0)\.0000000. * ( |0)\.0000000. * ( -|-0)\.5612620" $log | wc -l`
CRIT18=`$GREP "O * 17 * Vx = * ( |0)\.28063[0-9] * \-1\.68670[0-9] * (\-|\-0)\.60255[0-9]" $log | wc -l`
CRIT19=`$GREP "O * 17 * Vy = * ( |0)\.28063[0-9] * \-1\.68670[0-9] * (\-|\-0)\.60255[0-9]" $log | wc -l`
CRIT20=`$GREP "O * 17 * Vz = * (\-|\-0)\.56126[0-9] * 3\.37340[0-9] * 1\.20511[0-9]" $log | wc -l`
CRIT21=`$GREP "1-elec\. Darwin term: * 0*\.2604865[45]" $log | wc -l`
CRIT22=`$GREP "Mass-Velocity term: * \-0*\.32719552" $log | wc -l`
CRIT23=`$GREP "Mass-Velocity \+ 1\-elec\. Darwin terms\: * \-0*\.06670897" $log | wc -l`
CRIT24=`$GREP "Ecorr = * -113\.0657981674" $log | wc -l`
TEST[3]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7  \+ $CRIT8  \+ $CRIT9  \+ $CRIT10 \+ \
              $CRIT11 \+ $CRIT12 \+ $CRIT13 \+ $CRIT14 \+ $CRIT15 \+ \
              $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ $CRIT19 \+ $CRIT20 \+ \
              $CRIT21 \+ $CRIT22 \+ $CRIT23 \+ $CRIT24`
CTRL[3]=24
ERROR[3]="CC2 FIRST ORDER PROPERTIES NOT CORRECT"

PASSED=1
for i in 1 2 3
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
